home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kmainwindow.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  37.0 KB  |  1,068 lines

  1. /*
  2.     This file is part of the KDE libraries
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License version 2 as published by the Free Software Foundation.
  7.  
  8.     This library is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.     Library General Public License for more details.
  12.  
  13.     You should have received a copy of the GNU Library General Public License
  14.     along with this library; see the file COPYING.LIB.  If not, write to
  15.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.     Boston, MA 02110-1301, USA.
  17.  
  18.  
  19. */
  20.  
  21. #ifndef KMAINWINDOW_H
  22. #define KMAINWINDOW_H
  23.  
  24. #include "kxmlguifactory.h"
  25. #include "kxmlguiclient.h"
  26. #include "kxmlguibuilder.h"
  27. #include <qmainwindow.h>
  28. #include <qmetaobject.h>
  29. #include <ktoolbar.h>
  30.  
  31. class KPopupMenu;
  32. class KXMLGUIFactory;
  33. class KConfig;
  34. class KHelpMenu;
  35. class KStatusBar;
  36. class QStatusBar;
  37. class KMenuBar;
  38. class KMWSessionManaged;
  39. class KMainWindowPrivate;
  40. class KAccel;
  41. class KToolBarMenuAction;
  42. class DCOPObject;
  43.  
  44. #define KDE_DEFAULT_WINDOWFLAGS WType_TopLevel | WDestructiveClose
  45.  
  46.  
  47. /**
  48.  * @short %KDE top level main window
  49.  *
  50.  * Top level widget that provides toolbars, a status line and a frame.
  51.  *
  52.  * It should be used as a top level (parent-less) widget.
  53.  * It manages the geometry for all its children, including your
  54.  * main widget.
  55.  *
  56.  * Normally, you will inherit from KMainWindow,
  57.  * then construct (or use some existing) widget as
  58.  * your main view. You can set only one main view.
  59.  *
  60.  * You can add as many toolbars as you like. There can be only one menubar
  61.  * and only one statusbar.
  62.  *
  63.  * The toolbars, menubar, and statusbar can be created by the
  64.  * KMainWindow and - unlike the old KMainWindow - may, but do not
  65.  * have to, be deleted by you. KMainWindow will handle that internally.
  66.  *
  67.  * Height and width can be operated independently from each other. Simply
  68.  * define the minimum/maximum height/width of your main widget and
  69.  * KMainWindow will take this into account. For fixed size windows set
  70.  * your main widget to a fixed size.
  71.  *
  72.  * Fixed aspect ratios (heightForWidth()) and fixed width widgets are
  73.  * not supported.
  74. *
  75.  * KMainWindow will set icon, mini icon and caption, which it gets
  76.  * from KApplication. It provides full session management, and
  77.  * will save its position, geometry and positions of toolbars and
  78.  * menubar on logout. If you want to save additional data, reimplement
  79.  * saveProperties() and (to read them again on next login)
  80.  * readProperties(). To save special data about your data, reimplement
  81.  * saveGlobalProperties(). To warn user that application or
  82.  * windows have unsaved data on close or logout, reimplement
  83.  * queryClose() and/or queryExit().
  84.  *
  85.  * There are also kRestoreMainWindows convenience functions which
  86.  * can restore all your windows on next login.
  87.  *
  88.  *  Note that a KMainWindow per-default is created with the
  89.  *  WDestructiveClose flag, i.e. it is automatically destroyed when the
  90.  *  window is closed. If you do not want this behavior, specify 0 as
  91.  *  widget flag in the constructor.
  92.  *
  93.  * @see KApplication
  94.  * @author Reginald Stadlbauer (reggie@kde.org) Stephan Kulow (coolo@kde.org), Matthias Ettrich (ettrich@kde.org), Chris Schlaeger (cs@kde.org), Sven Radej (radej@kde.org). Maintained by Sven Radej (radej@kde.org)
  95.  
  96.  */
  97.  
  98. class KDEUI_EXPORT KMainWindow : public QMainWindow, public KXMLGUIBuilder, virtual public KXMLGUIClient
  99. {
  100.     friend class KMWSessionManaged;
  101.     Q_OBJECT
  102.  
  103. public:
  104.     /**
  105.      * Construct a main window.
  106.      *
  107.      * @param parent The widget parent. This is usually 0 but it may also be the window
  108.      * group leader. In that case, the KMainWindow becomes sort of a
  109.      * secondary window.
  110.      *
  111.      * @param name The object name. For session management and window management to work
  112.      * properly, all main windows in the application should have a
  113.      * different name. When passing 0 (the default), KMainWindow will create
  114.      * a unique name, but it's recommended to explicitly pass a window name that will
  115.      * also describe the type of the window. If there can be several windows of the same
  116.      * type, append '#' (hash) to the name, and KMainWindow will append numbers to make
  117.      * the names unique. For example, for a mail client which has one main window showing
  118.      * the mails and folders, and which can also have one or more windows for composing
  119.      * mails, the name for the folders window should be e.g. "mainwindow" and
  120.      * for the composer windows "composer#".
  121.      *
  122.      * @param f Specify the widget flags. The default is
  123.      * WType_TopLevel and WDestructiveClose.  TopLevel indicates that a
  124.      * main window is a toplevel window, regardless of whether it has a
  125.      * parent or not. DestructiveClose indicates that a main window is
  126.      * automatically destroyed when its window is closed. Pass 0 if
  127.      * you do not want this behavior.
  128.      *
  129.      * @see http://doc.trolltech.com/3.2/qt.html#WidgetFlags-enum
  130.      *
  131.      * KMainWindows must be created on the heap with 'new', like:
  132.      * \code
  133.      * KMainWindow *kmw = new KMainWindow (...);
  134.      * \endcode
  135.      **/
  136.     KMainWindow( QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
  137.  
  138.     /**
  139.      * Flags that can be passed in an argument to the constructor to
  140.      * change the behavior.
  141.      *
  142.      * NoDCOPObject tells KMainWindow not to create a KMainWindowInterface.
  143.      * This can be useful in particular for inherited classes, which
  144.      * might want to create more specific dcop interfaces. It's a good
  145.      * idea to use KMainWindowInterface as the base class for such interfaces
  146.      * though (to provide the standard mainwindow functionality via DCOP).
  147.      */
  148.     enum CreationFlags
  149.     {
  150.         NoDCOPObject = 1
  151.     };
  152.  
  153.     /**
  154.      * Overloaded constructor which allows passing some KMainWindow::CreationFlags.
  155.      *
  156.      * @since 3.2
  157.      */
  158.     KMainWindow( int cflags, QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
  159.  
  160.     /**
  161.      * \brief Destructor.
  162.      *
  163.      * Will also destroy the toolbars, and menubar if
  164.      * needed.
  165.      */
  166.     virtual ~KMainWindow();
  167.  
  168.     /**
  169.      * Retrieve the standard help menu.
  170.      *
  171.      * It contains entires for the
  172.      * help system (activated by F1), an optional "What's This?" entry
  173.      * (activated by Shift F1), an application specific dialog box,
  174.      * and an "About KDE" dialog box.
  175.      *
  176.      * Example (adding a standard help menu to your application):
  177.      * \code
  178.      * KPopupMenu *help = helpMenu( <myTextString> );
  179.      * menuBar()->insertItem( i18n("&Help"), help );
  180.      * \endcode
  181.      *
  182.      * @param aboutAppText The string that is used in the application
  183.      *        specific dialog box. If you leave this string empty the
  184.      *        information in the global KAboutData of the
  185.      *        application will be used to make a standard dialog box.
  186.      *
  187.      * @param showWhatsThis Set this to false if you do not want to include
  188.      *        the "What's This" menu entry.
  189.      *
  190.      * @return A standard help menu.
  191.      */
  192.     KPopupMenu* helpMenu( const QString &aboutAppText = QString::null,
  193.               bool showWhatsThis = true );
  194.  
  195.     /**
  196.      * Returns the help menu. Creates a standard help menu if none exists yet.
  197.      *
  198.      * It contains entries for the
  199.      * help system (activated by F1), an optional "What's This?" entry
  200.      * (activated by Shift F1), an application specific dialog box,
  201.      * and an "About KDE" dialog box. You must create the application
  202.      * specific dialog box yourself. When the "About application"
  203.      * menu entry is activated, a signal will trigger the
  204.      * showAboutApplication slot. See showAboutApplication for more
  205.      * information.
  206.      *
  207.      * Example (adding a help menu to your application):
  208.      * \code
  209.      * menuBar()->insertItem( i18n("&Help"), customHelpMenu() );
  210.      * \endcode
  211.      *
  212.      * @param showWhatsThis Set this to @p false if you do not want to include
  213.      *        the "What's This" menu entry.
  214.      *
  215.      * @return A standard help menu.
  216.      */
  217.     KPopupMenu* customHelpMenu( bool showWhatsThis = true );
  218.  
  219.     /**
  220.      * <b>Session Management</b>
  221.      *
  222.      * Try to restore the toplevel widget as defined by the number (1..X).
  223.      *
  224.      * If the session did not contain so high a number, the configuration
  225.      * is not changed and @p false returned.
  226.      *
  227.      * That means clients could simply do the following:
  228.      * \code
  229.      * if (kapp->isRestored()){
  230.      *   int n = 1;
  231.      *   while (KMainWindow::canBeRestored(n)){
  232.      *     (new childMW)->restore(n);
  233.      *     n++;
  234.      *   }
  235.      * } else {
  236.      *   // create default application as usual
  237.      * }
  238.      * \endcode
  239.      * Note that QWidget::show() is called implicitly in restore.
  240.      *
  241.      * With this you can easily restore all toplevel windows of your
  242.      * application.
  243.      *
  244.      * If your application uses different kinds of toplevel
  245.      * windows, then you can use KMainWindow::classNameOfToplevel(n)
  246.      * to determine the exact type before calling the childMW
  247.      * constructor in the example from above.
  248.      *
  249.      * If your client has only one kind of toplevel widgets (which
  250.      * should be pretty usual) then you should use the RESTORE-macro
  251.      * for backwards compatibility with 3.1 and 3.0 branches:
  252.      *
  253.      * \code
  254.      * if (kapp->isRestored())
  255.      *   RESTORE(childMW)
  256.      * else {
  257.      *   // create default application as usual
  258.      * }
  259.      * \endcode
  260.      *
  261.      * The macro expands to the term above but is easier to use and
  262.      * less code to write.
  263.      *
  264.      * For new code or if you have more than one kind of toplevel
  265.      * widget (each derived from KMainWindow, of course), you can
  266.      * use the templated kRestoreMainWindows global functions:
  267.      *
  268.      * \code
  269.      * if (kapp->isRestored())
  270.      *   kRestoreMainWindows< childMW1, childMW2, childMW3 >();
  271.      * else {
  272.      *   // create default application as usual
  273.      * }
  274.      * \endcode
  275.      *
  276.      * Currently, these functions are provided for up to three
  277.      * template arguments. If you need more, tell us. To help you in
  278.      * deciding whether or not you can use kRestoreMainWindows, a
  279.      * define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS is provided.
  280.      *
  281.      * @see restore()
  282.      * @see classNameOfToplevel()
  283.      *
  284.      **/
  285.     static bool canBeRestored( int number );
  286.  
  287.     /**
  288.      * Returns the className() of the @p number of the toplevel window which
  289.      * should be restored.
  290.      *
  291.      * This is only useful if your application uses
  292.      * different kinds of toplevel windows.
  293.      */
  294.     // KDE 4 return QCString - QObject::className() returns const char*
  295.     static const QString classNameOfToplevel( int number );
  296.  
  297.     /**
  298.      * Reimplementation of QMainWindow::show()
  299.      */
  300.     // KDE4 remove this method if this has been fixed in Qt
  301.     virtual void show();
  302.  
  303.     /**
  304.      * Reimplementation of QMainWindow::hide()
  305.      */
  306.     // KDE4 remove this method if this has been fixed in Qt
  307.     virtual void hide();
  308.  
  309.     /**
  310.      * Restore the session specified by @p number.
  311.      *
  312.      * Returns @p false if this
  313.      * fails, otherwise returns @p true and shows the window.
  314.      * You should call canBeRestored() first.
  315.      * If @p show is true (default), this widget will be shown automatically.
  316.      */
  317.     bool restore( int number, bool show = true );
  318.  
  319.     virtual KXMLGUIFactory *guiFactory();
  320.  
  321.     /**
  322.      * Create a GUI given a local XML file.
  323.      *
  324.      * If @p xmlfile is NULL,
  325.      * then it will try to construct a local XML filename like
  326.      * appnameui.rc where 'appname' is your app's name.  If that file
  327.      * does not exist, then the XML UI code will only use the global
  328.      * (standard) XML file for the layout purposes.
  329.      *
  330.      * Note that when passing true for the conserveMemory argument subsequent
  331.      * calls to guiFactory()->addClient/removeClient may not work as expected.
  332.      * Also retrieving references to containers like popup menus or toolbars using
  333.      * the container method will not work.
  334.      *
  335.      * @param xmlfile The local xmlfile (relative or absolute)
  336.      * @param _conserveMemory Specify whether createGUI() should call
  337.      * KXMLGUIClient::conserveMemory() to free all memory
  338.      *     allocated by the QDomDocument and by the KXMLGUIFactory.
  339.      */
  340.     void createGUI( const QString &xmlfile = QString::null, bool _conserveMemory = true );
  341.  
  342.     /**
  343.      * Enables the build of a standard help menu when calling createGUI().
  344.      *
  345.      * The default behavior is to build one, you must call this function
  346.      * to disable it
  347.      */
  348.     void setHelpMenuEnabled(bool showHelpMenu = true);
  349.  
  350.     /**
  351.      * Return @p true when the help menu is enabled
  352.      */
  353.     bool isHelpMenuEnabled();
  354.  
  355.  
  356.     /**
  357.      * Returns true, if there is a menubar
  358.      * @since 3.1
  359.      */
  360.      bool hasMenuBar();
  361.  
  362.     /**
  363.      * Returns a pointer to the menu bar.
  364.      *
  365.      * If there is no menu bar yet one will be created.
  366.      **/
  367.     KMenuBar *menuBar();
  368.  
  369.     /**
  370.      * Returns a pointer to the status bar.
  371.      *
  372.      * If there is no status bar yet, one will be created.
  373.      *
  374.      * Note that tooltips for kactions in actionCollection() are not
  375.      * automatically connected to this statusBar.
  376.      * See the KActionCollection documentation for more details.
  377.      *
  378.      * @see KActionCollection
  379.      */
  380.     KStatusBar *statusBar();
  381.  
  382.     /**
  383.      * List of members of KMainWindow class.
  384.      */
  385.     static QPtrList<KMainWindow>* memberList;
  386.  
  387.     //KDE4: replace with memberList() and make memberList member private
  388.     /**
  389.      * List of members of KMainWindow class.
  390.      * @since 3.4
  391.      */
  392.     static QPtrList<KMainWindow>* getMemberList();
  393.  
  394.     /**
  395.      * Returns a pointer to the toolbar with the specified name.
  396.      * This refers to toolbars created dynamically from the XML UI
  397.      * framework.  If the toolbar does not exist one will be created.
  398.      *
  399.      * @param name The internal name of the toolbar. If no name is
  400.      *             specified "mainToolBar" is assumed.
  401.      *
  402.      * @return A pointer to the toolbar
  403.      **/
  404.     KToolBar *toolBar( const char *name=0 );
  405.  
  406.     /**
  407.      * @return An iterator over the list of all toolbars for this window.
  408.      */
  409.     QPtrListIterator<KToolBar> toolBarIterator();
  410.  
  411.     /**
  412.      * @return A KAccel instance bound to this mainwindow. Used automatically
  413.      * by KAction to make keybindings work in all cases.
  414.      */
  415.     KAccel *accel();
  416.  
  417.     void setFrameBorderWidth( int ) {}
  418.  
  419.     /**
  420.      * Call this to enable "auto-save" of toolbar/menubar/statusbar settings
  421.      * (and optionally window size).
  422.      * If the *bars were moved around/shown/hidden when the window is closed,
  423.      * saveMainWindowSettings( KGlobal::config(), groupName ) will be called.
  424.      *
  425.      * @param groupName a name that identifies this "type of window".
  426.      * You can have several types of window in the same application.
  427.      *
  428.      * @param saveWindowSize set it to true to include the window size
  429.      * when saving.
  430.      *
  431.      * Typically, you will call setAutoSaveSettings() in your
  432.      * KMainWindow-inherited class constructor, and it will take care
  433.      * of restoring and saving automatically. Make sure you call this
  434.      * _after all_ your *bars have been created.
  435.      *
  436.      * To make sure that KMainWindow propertly obtains the default
  437.      * size of the window you should do the following:
  438.      * - Remove hard coded resize() calls in the constructor or main, they
  439.      *   should be removed in favor of letting the automatic resizing
  440.      *   determine the default window size.  Hard coded window sizes will
  441.      *   be wrong for users that have big fonts, use different styles,
  442.      *   long/small translations, large toolbars, and other factors.
  443.      * - Put the setAutoSaveSettings ( or setupGUI() ) call after all widgets
  444.      *   have been created and placed inside the main window (i.e. for 99% of
  445.      *   apps setCentralWidget())
  446.      * - Widgets that inherit from QWidget (like game boards) should overload
  447.      *   "virtual QSize sizeHint() const;" to specify a default size rather
  448.      *   than letting QWidget::adjust use the default size of 0x0.
  449.      */
  450.     void setAutoSaveSettings( const QString & groupName = QString::fromLatin1("MainWindow"),
  451.                               bool saveWindowSize = true );
  452.  
  453.     /**
  454.      * Disable the auto-save-settings feature.
  455.      * You don't normally need to call this, ever.
  456.      */
  457.     void resetAutoSaveSettings();
  458.  
  459.     /**
  460.      * @return the current autosave setting, i.e. true if setAutoSaveSettings() was called,
  461.      * false by default or if resetAutoSaveSettings() was called.
  462.      * @since 3.1
  463.      */
  464.     bool autoSaveSettings() const;
  465.  
  466.     /**
  467.      * @return the group used for setting-autosaving.
  468.      * Only meaningful if setAutoSaveSettings() was called.
  469.      * This can be useful for forcing a save or an apply, e.g. before and after
  470.      * using KEditToolbar.
  471.      * @since 3.1
  472.      */
  473.     QString autoSaveGroup() const;
  474.  
  475.     /**
  476.      * Read settings for statusbar, menubar and toolbar from their respective
  477.      * groups in the config file and apply them.
  478.      *
  479.      * @param config Config file to read the settings from.
  480.      * @param groupName Group name to use. If not specified, the last used
  481.      * group name is used.
  482.      * @param force if set, even default settings are re-applied
  483.      */
  484.     void applyMainWindowSettings(KConfig *config, const QString &groupName, bool force);
  485.     // KDE4 merge with force=false
  486.     void applyMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
  487.  
  488.     /**
  489.      * Save settings for statusbar, menubar and toolbar to their respective
  490.      * groups in the config file @p config.
  491.      *
  492.      * @param config Config file to save the settings to.
  493.      * @param groupName Group name to use. If not specified, the last used
  494.      * group name is used
  495.      */
  496.     void saveMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
  497.  
  498.     /**
  499.      * Sets whether KMainWindow should provide a menu that allows showing/hiding
  500.      * the available toolbars ( using KToggleToolBarAction ) . In case there
  501.      * is only one toolbar configured a simple 'Show \<toolbar name here\>' menu item
  502.      * is shown.
  503.      *
  504.      * The menu / menu item is implemented using xmlgui. It will be inserted in your
  505.      * menu structure in the 'Settings' menu.
  506.      *
  507.      * If your application uses a non-standard xmlgui resource file then you can
  508.      * specify the exact position of the menu / menu item by adding a
  509.      * <Merge name="StandardToolBarMenuHandler" />
  510.      * line to the settings menu section of your resource file ( usually appname.rc ).
  511.      *
  512.      * Note that you should enable this feature before calling createGUI() ( or similar ) .
  513.      * You enable/disable it anytime if you pass false to the conserveMemory argument of createGUI.
  514.      * @since 3.1
  515.      */
  516.     void setStandardToolBarMenuEnabled( bool enable );
  517.     /// @since 3.1
  518.     bool isStandardToolBarMenuEnabled() const;
  519.  
  520.  
  521.     /**
  522.      * Sets whether KMainWindow should provide a menu that allows showing/hiding
  523.      * of the statusbar ( using KToggleStatusBarAction ).
  524.      *
  525.      * The menu / menu item is implemented using xmlgui. It will be inserted
  526.      * in your menu structure in the 'Settings' menu.
  527.      *
  528.      * Note that you should enable this feature before calling createGUI()
  529.      * ( or similar ).
  530.      *
  531.      * If an application maintains the action on its own (i.e. never calls
  532.      * this function) a connection needs to be made to let KMainWindow
  533.      * know when that status (hidden/shown) of the statusbar has changed.
  534.      * For example:
  535.      * connect(action, SIGNAL(activated()),
  536.      *         kmainwindow, SLOT(setSettingsDirty()));
  537.      * Otherwise the status (hidden/show) of the statusbar might not be saved
  538.      * by KMainWindow.
  539.      * @since 3.2
  540.      */
  541.     void createStandardStatusBarAction();
  542.  
  543.     /**
  544.      * @see setupGUI()
  545.      */
  546.     enum StandardWindowOptions
  547.     {
  548.         /**
  549.          * adds action to show/hide the toolbar(s) and adds
  550.          * action to configure the toolbar(s).
  551.          * @see setStandardToolBarMenuEnabled
  552.          */
  553.         ToolBar = 1,
  554.  
  555.         /**
  556.          * adds action to show the key configure action.
  557.          */
  558.         Keys = 2,
  559.  
  560.         /**
  561.          * adds action to show/hide the statusbar if the
  562.          * statusbar exists.  See createStandardStatusBarAction
  563.          */
  564.         StatusBar = 4,
  565.  
  566.         /**
  567.          * auto-saves (and loads) the toolbar/menubar/statusbar settings and
  568.          * window size using the default name.  See setAutoSaveSettings
  569.          *
  570.          * Typically you want to let the default window size be determined by
  571.          * the widgets size hints. Make sure that setupGUI() is called after
  572.          * all the widgets are created ( including setCentralWidget ) so the
  573.          * default size's will be correct. See setAutoSaveSettings for
  574.          * more information on this topic.
  575.          */
  576.         Save = 8,
  577.  
  578.         /**
  579.          * calls createGUI() once ToolBar, Keys and Statusbar have been
  580.          * taken care of.  See createGUI
  581.          */
  582.         Create = 16
  583.     };
  584.  
  585.     /**
  586.      * Configures the current windows and its actions in the typical KDE
  587.      * fashion.  The options are all enabled by default but can be turned
  588.      * off if desired through the params or if the prereqs don't exists.
  589.      *
  590.      * Typically this function replaces createGUI().
  591.      *
  592.      * @see StandardWindowOptions
  593.      *
  594.      * @since 3.3
  595.      */
  596.     void setupGUI( int options = ToolBar | Keys | StatusBar | Save | Create, const QString& xmlfile = QString::null );
  597.  
  598.     /**
  599.      * Configures the current windows and its actions in the typical KDE
  600.      * fashion.  The options are all enabled by default but can be turned
  601.      * off if desired through the params or if the prereqs don't exists.
  602.      *
  603.      * @p defaultSize The default size of the window
  604.      *
  605.      * Typically this function replaces createGUI().
  606.      *
  607.      * @see StandardWindowOptions
  608.      *
  609.      * @since 3.5
  610.      */
  611.     void setupGUI( QSize defaultSize, int options = ToolBar | Keys | StatusBar | Save | Create, const QString& xmlfile = QString::null );
  612.  
  613.     /**
  614.      * Returns a pointer to the mainwindows action responsible for the toolbars menu
  615.      * @since 3.1
  616.      */
  617.     KAction *toolBarMenuAction();
  618.  
  619.     /**
  620.      * @internal for KToolBar
  621.      * @since 3.3.1
  622.      */
  623.     void setupToolbarMenuActions();
  624.  
  625.     // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI;
  626.     /// @since 3.1
  627.     virtual void finalizeGUI( KXMLGUIClient *client );
  628.  
  629.     /**
  630.      * @internal
  631.      */
  632.     void finalizeGUI( bool force );
  633.  
  634.     /**
  635.      * @return true if a -geometry argument was given on the command line,
  636.      * and this is the first window created (the one on which this option applies)
  637.      */
  638.     bool initialGeometrySet() const;
  639.  
  640.     /**
  641.      * @internal
  642.      * Used from Konqueror when reusing the main window.
  643.      */
  644.     void ignoreInitialGeometry();
  645.  
  646.     /**
  647.      * @return the size the mainwindow should have so that the central
  648.      * widget will be of @p size.
  649.      *
  650.      * @deprecated You normally don't need this, the recommended way to achieve a
  651.      *   certain central widget size is as follows:
  652.      *     @li Override sizeHint() in the central widget so that it
  653.      *      returns the desired size.
  654.      *     @li Call updateGeometry() in the central widget whenever the
  655.      *      desired size changes. This ensures that the new sizeHint() is properly
  656.      *      propagated to any parent layout.
  657.      *     @li Now call adjustSize() in the mainwindow to resize the
  658.      *      mainwindow such that the central widget will become the desired size.
  659.      *
  660.      */
  661.     // KDE4 to be removed
  662.     QSize sizeForCentralWidgetSize(QSize size) KDE_DEPRECATED;
  663.  
  664.     /**
  665.      * @internal
  666.      */
  667.     // KDE4 remove
  668.     virtual void setIcon( const QPixmap & );
  669.  
  670. public slots:
  671.     /**
  672.      * Show a standard configure toolbar dialog.
  673.      *
  674.      * This slot can be connected dirrectly to the action to configure shortcuts.
  675.      * This is very simple to do that by adding a single line
  676.      * \code
  677.      * KStdAction::configureToolbars( guiFactory(), SLOT( configureToolbars() ),
  678.      *                                actionCollection() );
  679.      * \endcode
  680.      *
  681.      * @since 3.3
  682.      */
  683.    int configureToolbars(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow
  684.  
  685.     /**
  686.      * Makes a KDE compliant caption.
  687.      *
  688.      * @param caption Your caption. @em Do @em not include the application name
  689.      * in this string. It will be added automatically according to the KDE
  690.      * standard.
  691.      */
  692.     virtual void setCaption( const QString &caption );
  693.     /**
  694.      * Makes a KDE compliant caption.
  695.      *
  696.      * @param caption Your caption. @em Do @em not include the application name
  697.      * in this string. It will be added automatically according to the KDE
  698.      * standard.
  699.      * @param modified Specify whether the document is modified. This displays
  700.      * an additional sign in the title bar, usually "**".
  701.      */
  702.     virtual void setCaption( const QString &caption, bool modified );
  703.  
  704.     /**
  705.      * Make a plain caption without any modifications.
  706.      *
  707.      * @param caption Your caption. This is the string that will be
  708.      * displayed in the window title.
  709.      */
  710.     virtual void setPlainCaption( const QString &caption );
  711.  
  712.     /**
  713.      * Open the help page for the application.
  714.      *
  715.      *  The application name is
  716.      * used as a key to determine what to display and the system will attempt
  717.      * to open \<appName\>/index.html.
  718.      *
  719.      * This method is intended for use by a help button in the toolbar or
  720.      * components outside the regular help menu. Use helpMenu() when you
  721.      * want to provide access to the help system from the help menu.
  722.      *
  723.      * Example (adding a help button to the first toolbar):
  724.      *
  725.      * \code
  726.      * KIconLoader &loader = *KGlobal::iconLoader();
  727.      * QPixmap pixmap = loader.loadIcon( "help" );
  728.      * toolBar(0)->insertButton( pixmap, 0, SIGNAL(clicked()),
  729.      *   this, SLOT(appHelpActivated()), true, i18n("Help") );
  730.      * \endcode
  731.      *
  732.      */
  733.     void appHelpActivated( void );
  734.  
  735.     /**
  736.      * Apply a state change
  737.      *
  738.      * Enable and disable actions as defined in the XML rc file
  739.      * @since 3.1
  740.      */
  741.     virtual void slotStateChanged(const QString &newstate);
  742.  
  743.     /**
  744.      * Apply a state change
  745.      *
  746.      * Enable and disable actions as defined in the XML rc file,
  747.      * can "reverse" the state (disable the actions which should be
  748.      * enabled, and vice-versa) if specified.
  749.      * @since 3.1
  750.      */
  751.     void slotStateChanged(const QString &newstate,
  752.                           KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this
  753.  
  754.  
  755.     /**
  756.      * Apply a state change
  757.      *
  758.      * Enable and disable actions as defined in the XML rc file,
  759.      * can "reverse" the state (disable the actions which should be
  760.      * enabled, and vice-versa) if specified.
  761.      */
  762. //     void slotStateChanged(const QString &newstate,
  763. //                           bool reverse); // KDE 4.0: enable this
  764.  
  765.     /**
  766.      * Tell the main window that it should save its settings when being closed.
  767.      * This is part of the auto-save-settings feature.
  768.      * For everything related to toolbars this happens automatically,
  769.      * but you have to call setSettingsDirty() in the slot that toggles
  770.      * the visibility of the statusbar.
  771.      */
  772.     void setSettingsDirty();
  773.  
  774. protected:
  775.     void paintEvent( QPaintEvent* e );
  776.     void childEvent( QChildEvent* e);
  777.     void resizeEvent( QResizeEvent* e);
  778.     /**
  779.      * Reimplemented to call the queryClose() and queryExit() handlers.
  780.      *
  781.      * We recommend that you reimplement the handlers rather than closeEvent().
  782.      * If you do it anyway, ensure to call the base implementation to keep
  783.      * queryExit() running.
  784.      */
  785.     virtual void closeEvent ( QCloseEvent *);
  786.  
  787.     // KDE4 This seems to be flawed to me. Either the app has only one
  788.     // mainwindow, so queryClose() is enough, or if it can have more of them,
  789.     // then the windows should take care of themselves, and queryExit()
  790.     // would be useful only for the annoying 'really quit' dialog, which
  791.     // also doesn't make sense in apps with multiple mainwindows.
  792.     // And saving configuration in something called queryExit()? IMHO
  793.     // one can e.g. use KApplication::shutDown(), which if nothing else
  794.     // has at least better fitting name.
  795.     // See also KApplication::sessionSaving().
  796.     // This stuff should get changed somehow, so that it at least doesn't
  797.     // mess with session management.
  798.     /**
  799.        Called before the very last window is closed, either by the
  800.        user or indirectly by the session manager.
  801.  
  802.        It is not recommended to do any user interaction in this
  803.        function other than indicating severe errors. Better ask the
  804.        user on queryClose() (see below).
  805.  
  806.        A typical usage of queryExit() is to write configuration data back.
  807.        Note that the application may continue to run after queryExit()
  808.        (the user may have canceled a shutdown), so you should not do any cleanups
  809.        here. The purpose of queryExit() is purely to prepare the application
  810.        (with possible user interaction) so it can safely be closed later (without
  811.        user interaction).
  812.  
  813.        If you need to do serious things on exit (like shutting a
  814.        dial-up connection down), connect to the signal
  815.  KApplication::shutDown().
  816.  
  817.        Default implementation returns @p true. Returning @p false will
  818.        cancel the exiting. In the latter case, the last window will
  819.        remain visible. If KApplication::sessionSaving() is true, refusing
  820.        the exit will also cancel KDE logout.
  821.  
  822.        @see queryClose()
  823.        @see KApplication::sessionSaving()
  824.      */
  825.     virtual bool queryExit();
  826.  
  827.     /**
  828.        Called before the window is closed, either by the user or indirectly by
  829.        the session manager.
  830.  
  831.        The purpose of this function is to prepare the window in a way that it is
  832.        safe to close it, i.e. without the user losing some data.
  833.  
  834.        Default implementation returns true. Returning @p false will cancel
  835.        the closing, and, if KApplication::sessionSaving() is true, it will also
  836.        cancel KDE logout.
  837.  
  838.        Reimplement this function to prevent the user from losing data.
  839.        Example:
  840.        \code
  841.        switch ( KMessageBox::warningYesNoCancel( this,
  842.                 i18n("Save changes to document foo?")) ) {
  843.        case KMessageBox::Yes :
  844.          // save document here. If saving fails, return false;
  845.          return true;
  846.        case KMessageBox::No :
  847.          return true;
  848.        default: // cancel
  849.          return false;
  850.        \endcode
  851.  
  852.        Note that you should probably @em not actually close the document from
  853.        within this method, as it may be called by the session manager before the
  854.        session is saved. If the document is closed before the session save occurs,
  855.        its location might not be properly saved. In addition, the session shutdown
  856.        may be canceled, in which case the document should remain open.
  857.  
  858.        @see queryExit()
  859.        @see KApplication::sessionSaving()
  860.     */
  861.     virtual bool queryClose();
  862.  
  863.     /**
  864.      * Save your instance-specific properties. The function is
  865.      * invoked when the session manager requests your application
  866.      * to save its state.
  867.      *
  868.      * You @em must @em not change the group of the @p kconfig object, since
  869.      * KMainWindow uses one group for each window.  Please
  870.      * reimplement these function in childclasses.
  871.      *
  872.      * Note: No user interaction is allowed
  873.      * in this function!
  874.      *
  875.      */
  876.     virtual void saveProperties( KConfig* ) {}
  877.  
  878.    /**
  879.     * Read your instance-specific properties.
  880.     */
  881.     virtual void readProperties( KConfig* ) {}
  882.  
  883.    /**
  884.      * Save your application-wide properties. The function is
  885.      * invoked when the session manager requests your application
  886.      * to save its state.
  887.      *
  888.      * This function is similar to saveProperties() but is only called for
  889.      * the very first main window, regardless how many main window are open.
  890.  
  891.      * Override it if you need to save other data about your documents on
  892.      * session end. sessionConfig is a config to which that data should be
  893.      * saved. Normally, you don't need this function. But if you want to save
  894.      * data about your documents that are not in opened windows you might need
  895.      * it.
  896.      *
  897.      * Default implementation does nothing.
  898.      */
  899.     virtual void saveGlobalProperties( KConfig* sessionConfig );
  900.  
  901.     /**
  902.      * The counterpart of saveGlobalProperties().
  903.      *
  904.      * Read the application-specific properties in again.
  905.      */
  906.     virtual void readGlobalProperties( KConfig* sessionConfig );
  907.     void savePropertiesInternal( KConfig*, int );
  908.     bool readPropertiesInternal( KConfig*, int );
  909.  
  910.     /**
  911.      * For inherited classes
  912.      */
  913.     bool settingsDirty() const;
  914.     /**
  915.      * For inherited classes
  916.      */
  917.     QString settingsGroup() const;
  918.     /**
  919.      * For inherited classes
  920.      * Note that the group must be set before calling
  921.      */
  922.     void saveWindowSize( KConfig * config ) const;
  923.     /**
  924.      * For inherited classes
  925.      * Note that the group must be set before calling, and that
  926.      * a -geometry on the command line has priority.
  927.      */
  928.     void restoreWindowSize( KConfig * config );
  929.  
  930.     /// parse the geometry from the geometry command line argument
  931.     void parseGeometry(bool parsewidth);
  932.  
  933. protected slots:
  934.    /**
  935.     * Rebuilds the GUI after KEditToolbar changed the toolbar layout.
  936.     * @see configureToolbars()
  937.     */
  938.    void saveNewToolbarConfig(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow
  939.  
  940.     /**
  941.     * This slot does nothing.
  942.     *
  943.     * It must be reimplemented if you want
  944.     * to use a custom About Application dialog box. This slot is
  945.     * connected to the About Application entry in the menu returned
  946.     * by customHelpMenu.
  947.     *
  948.     * Example:
  949.     * \code
  950.     *
  951.     * void MyMainLevel::setupInterface()
  952.     * {
  953.     *   ..
  954.     *   menuBar()->insertItem( i18n("&Help"), customHelpMenu() );
  955.     *   ..
  956.     * }
  957.     *
  958.     * void MyMainLevel::showAboutApplication()
  959.     * {
  960.     *   <activate your custom dialog>
  961.     * }
  962.     * \endcode
  963.     */
  964.     virtual void showAboutApplication();
  965.  
  966.    /**
  967.     * This slot should only be called in case you reimplement closeEvent() and
  968.     * if you are using the "auto-save" feature. In all other cases,
  969.     * setSettingsDirty() should be called instead to benefit from the delayed
  970.     * saving.
  971.     *
  972.     * @see setAutoSaveSettings
  973.     * @see setSettingsDirty
  974.     *
  975.     * @since 3.2
  976.     *
  977.     * Example:
  978.     * \code
  979.     *
  980.     * void MyMainWindow::closeEvent( QCloseEvent *e )
  981.     * {
  982.     *   // Save settings if auto-save is enabled, and settings have changed
  983.     *   if ( settingsDirty() && autoSaveSettings() )
  984.     *     saveAutoSaveSettings();
  985.     *   ..
  986.     * }
  987.     * \endcode
  988.     */
  989.     void saveAutoSaveSettings();
  990.  
  991. private slots:
  992.    /**
  993.     * Called when the app is shutting down.
  994.     */
  995.     void shuttingDown();
  996.  
  997. private:
  998.     KMenuBar *internalMenuBar();
  999.     KStatusBar *internalStatusBar();
  1000.     KHelpMenu *mHelpMenu, *helpMenu2;
  1001.     KXMLGUIFactory *factory_;
  1002.     QPtrList<KToolBar> toolbarList;
  1003. protected:
  1004.     virtual void virtual_hook( int id, void* data );
  1005. private:
  1006.     KMainWindowPrivate *d;
  1007.     void initKMainWindow(const char *name, int cflags);
  1008. };
  1009.  
  1010. #define RESTORE(type) { int n = 1;\
  1011.     while (KMainWindow::canBeRestored(n)){\
  1012.       (new type)->restore(n);\
  1013.       n++;}}
  1014.  
  1015. #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
  1016.  
  1017. /**
  1018.  *  These global convenience functions (that come with a varying
  1019.  *  number of template arguments) are a replacement for the RESTORE
  1020.  *  macro provided in earlier versions of KDE. The old RESTORE macro
  1021.  *  is still provided for backwards compatibility. See
  1022.  *  KMainWindow documentation for more.
  1023.  *
  1024.  * \since KDE 3.2
  1025.  *
  1026.  **/
  1027. template <typename T>
  1028. inline void kRestoreMainWindows() {
  1029.   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
  1030.     const QString className = KMainWindow::classNameOfToplevel( n );
  1031.     if ( className == QString::fromLatin1( T::staticMetaObject()->className() ) )
  1032.       (new T)->restore( n );
  1033.   }
  1034. }
  1035.  
  1036. template <typename T0, typename T1>
  1037. inline void kRestoreMainWindows() {
  1038.   const char * classNames[2];
  1039.   classNames[0] = T0::staticMetaObject()->className();
  1040.   classNames[1] = T1::staticMetaObject()->className();
  1041.   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
  1042.     const QString className = KMainWindow::classNameOfToplevel( n );
  1043.     if ( className == QString::fromLatin1( classNames[0] ) )
  1044.       (new T0)->restore( n );
  1045.     else if ( className == QString::fromLatin1( classNames[1] ) )
  1046.       (new T1)->restore( n );
  1047.   }
  1048. }
  1049.  
  1050. template <typename T0, typename T1, typename T2>
  1051. inline void kRestoreMainWindows() {
  1052.   const char * classNames[3];
  1053.   classNames[0] = T0::staticMetaObject()->className();
  1054.   classNames[1] = T1::staticMetaObject()->className();
  1055.   classNames[2] = T2::staticMetaObject()->className();
  1056.   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
  1057.     const QString className = KMainWindow::classNameOfToplevel( n );
  1058.     if ( className == QString::fromLatin1( classNames[0] ) )
  1059.       (new T0)->restore( n );
  1060.     else if ( className == QString::fromLatin1( classNames[1] ) )
  1061.       (new T1)->restore( n );
  1062.     else if ( className == QString::fromLatin1( classNames[2] ) )
  1063.       (new T2)->restore( n );
  1064.   }
  1065. }
  1066.  
  1067. #endif
  1068.